package com.example.myhttp

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.example.myhttp.mvvm.HttpViewModel
import com.google.gson.JsonObject
import com.yang.http.HttpRequest

class MainViewModel : HttpViewModel() {

    // 1，刷新模板列表；0，没有更多数据了；-1，网络请求成功，结果有错，-2，网络请求出错
    var postHttpResult: MutableLiveData<JsonObject> = MutableLiveData()
    var errorResult: MutableLiveData<String> = MutableLiveData()



    /**
     * 获取初始化app数据
     */
    fun postApp() {
        launchHttpJSONObject({
            HttpRequest.getService(HttpApiService::class.java).postApp()
        }, onResult = { it ->
            Log.e("网络请求", "请求成功：$it")
            postHttpResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value = "请求失败：$code$msg"
            Log.e("网络请求", " postHomePageList commonLog - onFailed: $code, $msg")
        }) {
            Log.e("网络请求", "postAppInit onComplete")
        }
    }

}